package cn.ywang.concurrent.two;

import java.io.IOException;

/**
 * @author BeatificWang
 * @date 2019/7/21 18:20
 */
public class SynchronizedDemo2 {
	static Integer count = 0;

	public static void incr() {
		synchronized (count) {
			try {
				Thread.sleep(1);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			count++;
			System.out.println(count.hashCode());
		}
	}

	public static void main(String[] args) throws IOException, InterruptedException {
		for (int i = 0; i < 127; i++) {
			new Thread(() -> SynchronizedDemo2.incr()).start();
		}
		Thread.sleep(10000);
		System.out.println("result:" + count);
	}

}
